<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>6.6</title>
    <style>
        * {
            padding: 0;
            margin: 0;
            box-sizing: border-box;
        }

        li {
            list-style: none;
        }

        body {
            position: relative;
        }
        
        .tbody {
            width: 700px;
            height: 500px;
            background-color: whitesmoke;
            position: absolute;
            top: 300px;
            left: calc((100% - 700px)/2);
            border-radius: 20px;
            border: 1px solid;
        }



        .lis {
            width: 80%;
            height: 50px;
            background-color: crimson;
            text-align: left;
            margin: 20px 0;
            position: relative;
            top: 20%;
            left: 10%;
        }

        .inps {
            width: 40px;
            height: 40px;
            margin: 5px;
        }

        .sps {

            font-size: 30px;
            line-height: 50px;
        }

        .btns {
            width: 40px;
            height: 40px;
            position: absolute;
            top: 5px;
            right: 5%;
            border-radius: 30px;
        }

        .thead {
            width: 700px;
            height: 100px;
            background-color: aquamarine;
            position: relative;
            top: 170px;
            left: calc((100% - 700px)/2);
            border-radius: 30px;
        }

        .thead input {
            width: 100%;
            height: 100%;
            border-radius: 30px;
        }

        .thead button {
            width: 150px;
            height: 100px;
            position: absolute;
            right: 0%;
            border-top-right-radius: 30px;
            border-bottom-right-radius: 30px;
            font-size: 40px;
            background-color: pink;
        }

        .right_box {
            width: 200px;
            height: 500px;
            background-color: chartreuse;
            position: fixed;
            top: 300px;
            right: 25%;

        }

        .right_box li {
            width: 100%;
            height: 50px;
            background-color:deepskyblue;
            text-align: center;
            line-height: 50px;
            font-size: 20px;
            border-bottom: 1px solid;
        }
        .del_all{
            position: absolute;
            bottom: 0%;
        }
        .body_title {
            width: 696px;
            height: 50px;
            background-color: white;
            z-index: 10;
            border-radius: 20px;
            border-bottom-right-radius: 0;
            border-bottom: 1px solid;
        }

        .body_title button {
            width: 200px;
            height: 50px;
            font-size: 20px;
            background-color: aquamarine;
            border-top-left-radius: 20px;
            margin-right: 30px;
            border-top: 0;
            border-left: 0;
        }

        .body_title span {
            font-size: 20px;
            font-weight: 700;
        }
    </style>
</head>

<body>
    <div class="thead">
        <input type="text" placeholder="新增待办事项...">
        <button onclick="presentation()">提交</button>
    </div>
    <div class="tbody">
        <div class="body_title"><button onclick="all_click()">全部标为完成</button><span>今日事今日毕，勿将今事待明日!</span></div>
        <ul>
            
        </ul>

    </div>
    <div class="right_box">
        <ul>
            <li class="look_all">全部</li>
            <li class="completed">已完成</li>
            <li class="incomplete">未完成</li>
            <li class="del_all">删除全部</li>

        </ul>
    </div>
    <script>
        let matter_data = [{
            name: '打豆豆',
            is: false
        }, {
            name: '睡觉',
            is: false
        }, {
            name: '吃饭',
            is: true
        },]

        let tbody = document.querySelector('.tbody ul')//需要渲染数据的ul
        let matter_inp = document.querySelector('.thead input')//输入框
        let inps = document.querySelectorAll('.inps')//所有复选框
        let look_all =document.querySelector('.look_all')//查看所有
        window.onload = function () {
            data()
        }
        // 渲染
        function data() {
            tbody.innerHTML = ''
            matter_data.forEach((item, index) => {
                tbody.innerHTML += `
                    <li class="lis" ${item.is ? 'style="background-color:aqua;"' : ''}><input class="inps" ${item.is ? 'checked' : ''} onclick="inp_click(${index})" type="checkbox"><span class="sps">${item.name}</span><button class="btns" onclick="del(${index})">X</button></li>
                `
            })
        }
        // 添加
        function presentation() {
            matter_data.push({
                name: matter_inp.value,
                is: false
            })
            matter_inp.value=''
            data()
        }

        // 删除单个
        function del(index) {
            matter_data.splice(index, 1)
            data()
        }

        // 删除所有
        document.querySelector('.del_all').addEventListener('click', () => {
            let qd = confirm('确定删除所有事项吗?')
            if (qd) {
                matter_data.splice(0, matter_data.length)
                data()
            }
        })

        // 单选
        function inp_click(ind) {
            matter_data[ind].is = event.target.checked
            data()
        }
        // 全选
        function all_click() {
            matter_data.every(i => i.is = true)
            data()
        }
        // 查看全部
        look_all.addEventListener('click', () => {
            data()
        })

        // 已完成
        document.querySelector('.completed').addEventListener('click', () => {
            tbody.innerHTML = ''
            matter_data.forEach((item, index) => {
                if (item.is) {
                    tbody.innerHTML += `
                        <li class="lis"><input class="inps" ${item.is ? 'checked' : ''} onclick="inp_click(${index})" type="checkbox"><span class="sps">${item.name}</span><button class="btns" onclick="del(${index})">X</button></li>
                     `
                }
            })
        })
        // 未完成
        document.querySelector('.incomplete').addEventListener('click', (item, index) => {
            tbody.innerHTML = ''
            matter_data.forEach((item, index) => {
                if (!item.is) {
                    tbody.innerHTML += `
                        <li class="lis"><input class="inps" ${item.is ? 'checked' : ''} onclick="inp_click(${index})" type="checkbox"><span class="sps">${item.name}</span><button class="btns" onclick="del(${index})">X</button></li>
                     `
                }
            })
        })

    </script>
</body>

</html>